package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.service.TrainingSignService;
import com.amsp.oa.oademo.vo.TrainingSignVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "培训签到管理")
@RestController
@RequestMapping("/api/training-sign")
public class TrainingSignController {

    @Resource
    private TrainingSignService trainingSignService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public IPage<TrainingSignVO> page(
            @ApiParam("当前页") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("讲师姓名") @RequestParam(required = false) String trainer) {
        return trainingSignService.page(current, size, trainer);
    }

    @ApiOperation("获取详情")
    @GetMapping("/{id}")
    public TrainingSignVO getDetail(@PathVariable Long id) {
        return trainingSignService.getDetail(id);
    }

    @ApiOperation("保存或更新")
    @PostMapping("/save")
    public void save(@RequestBody TrainingSignVO vo) {
        trainingSignService.saveOrUpdateTransactional(vo);
    }

    @ApiOperation("批量删除")
    @PostMapping("/batch")
    public void removeBatch(@RequestBody List<Long> ids) {
        trainingSignService.removeByIdsTransactional(ids);
    }
}